const { WebError, ErrorCode } = require('@mctech/infra-core')

const BIZ_EXCEPTION_STATUS_CODE = 400
const ILLEGAL_ARGUMENT_EXCEPTION = 'illegal_argument_exception'
const BIZ_EXCEPTION = 'biz_exception'
const ILLEGAL_STATE_EXCEPTION = 'illegal_state_exception'

/**
 * 业务异常
 * @description
 * @author ran peng
 * @date 2019-05-31
 * @class BizException
 * @extends {WebError}
 */
class BizException extends WebError {
  constructor (message) {
    super(new BizExceptionMessage(message))
  }
}

/**
 * 非法状态异常
 * @description
 * @author ran peng
 * @date 2019-05-31
 * @class IllegalStateException
 * @extends {WebError}
 */
class IllegalStateException extends WebError {
  constructor (message) {
    super(new IllegalStateMessage(message))
  }
}

/**
 * 业务异常消息
 * @description
 * @author ran peng
 * @date 2019-05-31
 * @class BizExceptionMessage
 * @extends {ErrorCode}
 */
class BizExceptionMessage extends ErrorCode {
  constructor (message) {
    super(BIZ_EXCEPTION, message, null, BIZ_EXCEPTION_STATUS_CODE)
  }
}

/**
 * 非法参数异常消息
 * @description
 * @author ran peng
 * @date 2019-05-31
 * @class IllegalArgumentMessage
 * @extends {ErrorCode}
 */
class IllegalArgumentMessage extends ErrorCode {
  constructor (message) {
    super(ILLEGAL_ARGUMENT_EXCEPTION, message)
  }
}

class IllegalStateMessage extends ErrorCode {
  constructor (message) {
    super(ILLEGAL_STATE_EXCEPTION, message)
  }
}

module.exports = {
  BizException,
  IllegalStateException,
  IllegalArgumentMessage,
  IllegalStateMessage,
  BizExceptionMessage
}
